<?php

namespace maotool\captcha;

class CaptchaUtil
{

    public static function create($key = "ffdade342507824838446f8b4edba88f")
    {
        return new Captcha($key);
    }

    public static function getCode($key = "ffdade342507824838446f8b4edba88f")
    {
        return new Captcha($key);
    }

    public static function verify($code, $key = "ffdade342507824838446f8b4edba88f")
    {
        if (isset($_SESSION['maotool_captcha_' . md5($key)])) {
            return $_SESSION['maotool_captcha_' . md5($key)]->verify($code);
        } else {
            return false;
        }
    }

    /**
     * @param $key
     * @return CaptchaData|null
     */
    public static function get($key = "ffdade342507824838446f8b4edba88f")
    {
        if (isset($_SESSION['maotool_captcha_' . md5($key)])) {
            return $_SESSION['maotool_captcha_' . md5($key)];
        } else {
            return null;
        }
    }

}